<template>
  <div class="content">
    <div class="clear">
      <Form inline class="fl">
        <DatePicker
          type="daterange"
          split-panels
          placeholder="请选择时间段"
          class="w200 m-r10"
          format="yyyy-MM-dd"
          @on-change="getTime"
          v-model="getDate"
        ></DatePicker>
        <Button class="m-r10" v-on:click="getTimeGcollect(1)">今日</Button>
        <Button class="m-r10" v-on:click="getTimeGcollect(2)">近7天</Button>
        <Button class="m-r10" v-on:click="getTimeGcollect(3)">近30天</Button>
        <Button type="primary" v-on:click="getCollectListQuery">查询</Button>
      </Form>
    </div>
    <fieldset>
      <legend>汇总</legend>
      <div>
        <tbody>
          <tr>
            <td>
              累计到账ESTATE:
              <span
                class="blue"
              >{{ list.estateAccrual == null ? 0 : Fixed(list.estateAccrual,4) }}</span>
            </td>
            <td>
              累计到账USDT:
              <span
                class="blue"
              >{{ list.usdtAccrual == null ? 0 : Fixed(list.usdtAccrual,4) }}</span>
            </td>
            <td>
              累计提现ESTATE:
              <span
                class="blue"
              >{{ list.exuuWithdrawal == null ? 0 : Fixed(list.exuuWithdrawal,4) }}</span>
            </td>
            <td>
              累计提现USDT:
              <span
                class="blue"
              >{{ list.usdtWiwthdrawal == null ? 0 : Fixed(list.usdtWiwthdrawal,4) }}</span>
            </td>
            <td>
              累计充值ESTATE:
              <span
                class="blue"
              >{{ list.estateRecharge == null ? 0 : Fixed(list.estateRecharge,4) }}</span>
            </td>
            <td>
              累计充值USDT:
              <span
                class="blue"
              >{{ list.usdtRecharge == null ? 0 : Fixed(list.usdtRecharge,4) }}</span>
            </td>
             <td>
              累计扣除ESTATE:
              <span
                class="blue"
              >{{ list.estateReduceRecharge == null ? 0 : Fixed(list.estateReduceRecharge,4) }}</span>
            </td>
            <td>
              累计扣除USDT:
              <span
                class="blue"
              >{{ list.usdtReduceRecharge == null ? 0 : Fixed(list.usdtReduceRecharge,4) }}</span>
            </td>



            <!-- <td>累计理财（EXUU数量）:
							<span class="blue">{{ list.financialNum == null ? 0 : Fixed(list.financialNum,4) }}</span>
						</td>
						<td>累计推荐奖:
							<span class="blue">{{ list.recommend == null ? 0 : Fixed(list.recommend,4) }}</span>
						</td>
						<td>累计节点奖:
							<span class="blue">{{ list.noteAward == null ? 0 : Fixed(list.noteAward,4) }}</span>
						</td>
						<td>累计网点奖励:
							<span class="blue">{{ list.netReward == null ? 0 : Fixed(list.netReward,4) }}</span>
            </td>-->
          </tr>
        </tbody>
      </div>
    </fieldset>
    <fieldset>
      <legend>
        时间段汇总(
        <span v-text="day" id="today"></span>)
      </legend>
      <div>
        <table>
          <tbody>
            <tr>
              <td>
                累计到账ESTATE:
                <span
                  class="blue"
                >{{ timeGcollect.estateAccrual == null ? 0 : Fixed(timeGcollect.estateAccrual,4) }}</span>
              </td>
              <td>
                累计到账USDT:
                <span
                  class="blue"
                >{{ timeGcollect.usdtAccrual == null ? 0 : Fixed(timeGcollect.usdtAccrual,4) }}</span>
              </td>
              <td>
                累计提现ESTATE:
                <span
                  class="blue"
                >{{ timeGcollect.estateWithdrawal == null ? 0 : Fixed(timeGcollect.estateWithdrawal,4) }}</span>
              </td>
              <td>
                累计提现USDT:
                <span
                  class="blue"
                >{{ timeGcollect.usdtWiwthdrawal == null ? 0 : Fixed(timeGcollect.usdtWiwthdrawal,4) }}</span>
              </td>
              <td>
                累计充值ESTATE:
                <span
                  class="blue"
                >{{ timeGcollect.estateRecharge == null ? 0 : Fixed(timeGcollect.estateRecharge,4) }}</span>
              </td>
              <td>
                累计充值USDT:
                <span
                  class="blue"
                >{{ timeGcollect.usdtRecharge == null ? 0 : Fixed(timeGcollect.usdtRecharge,4) }}</span>
              </td>
              
                <td>
              累计扣除ESTATE:
              <span
                class="blue"
              >{{ timeGcollect.estateReduceRecharge == null ? 0 : Fixed(timeGcollect.estateReduceRecharge,4) }}</span>
            </td>
            <td>
              累计扣除USDT:
              <span
                class="blue"
              >{{ timeGcollect.usdtReduceRecharge == null ? 0 : Fixed(timeGcollect.usdtReduceRecharge,4) }}</span>
            </td>
              <!-- <td>累计理财（EXUU数量）:
								<span class="blue">{{ timeGcollect.financialNum == null ? 0 : Fixed(timeGcollect.financialNum,4) }}</span>
							</td>
							<td>累计推荐奖:
								<span class="blue">{{ timeGcollect.recommend == null ? 0 : Fixed(timeGcollect.recommend,4) }}</span>
							</td>
							<td>累计节点奖:
								<span class="blue">{{ timeGcollect.noteAward == null ? 0 : Fixed(timeGcollect.noteAward,4) }}</span>
							</td>
							<td>累计网点奖励:
								<span class="blue">{{ timeGcollect.netReward == null ? 0 : Fixed(timeGcollect.netReward,4) }}</span>
              </td>-->
            </tr>
          </tbody>
        </table>
      </div>
    </fieldset>
    <Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
      <Icon type="ios-download-outline"></Icon>导出
    </Button>
    <Table stripe :columns="columns" :data="collectList" ref="table" :loading="loading"></Table>
    <Page
      :total="info"
      :page-size="pageSize"
      show-elevator
      show-total
      @on-change="cuctGetCollectList"
      :current.sync="page"
    ></Page>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dcShow: false,
      loading: true,
      day: "", // 时间显示(今日,近7天,近30天)
      list: [], // 财务汇总统计
      timeGcollect: [], // 时间段汇总
      collectList: [], // 财务统计列表的数据
      dataValue: ["", ""], // 时间段值
      info: null, // 总条数
      page: 1, // 页数
      pageSize: 20, // 每页多少条
      getDate: "",
      current: 1,
      downList: [],
      jsonData: [],
      columns: [
        {
          title: "日期",
          key: "times",
          align: "center",
          sortable: true,
          fixed: "left",
          render: (h, params) => {
            return h("div", params.row.times == null ? "#" : params.row.times);
          }
        },
        {
          title: "累计到账ESTATE",
          align: "center",
          key: "estateAccrual",
          render: (h, params) => {
            return h(
              "div",
              params.row.estateAccrual == null
                ? "#"
                : this.Fixed(params.row.estateAccrual, 4)
            );
          }
        },
        {
          title: "累计到账USDT",
          align: "center",
          key: "usdtAccrual",
          render: (h, params) => {
            return h(
              "div",
              params.row.usdtAccrual == null
                ? "#"
                : this.Fixed(params.row.usdtAccrual, 4)
            );
          }
        },
        {
          title: "累计提现ESTATE",
          align: "center",
          key: "estateWithdrawal",
          render: (h, params) => {
            return h(
              "div",
              params.row.estateWithdrawal == null
                ? "#"
                : this.Fixed(params.row.estateWithdrawal, 4)
            );
          }
        },
        {
          title: "累计提现USDT",
          align: "center",
          key: "usdtWithdrawal",
          render: (h, params) => {
            return h(
              "div",
              params.row.usdtWithdrawal == null
                ? "#"
                : this.Fixed(params.row.usdtWithdrawal, 4)
            );
          }
        },
        {
          title: "累计充值ESTATE",
          align: "center",
          key: "estateRecharge",
          render: (h, params) => {
            return h(
              "div",
              params.row.estateRecharge == null
                ? "#"
                : this.Fixed(params.row.estateRecharge, 4)
            );
          }
        },
        {
          title: "累计充值USDT",
          align: "center",
          key: "usdtRecharge",
          render: (h, params) => {
            return h(
              "div",
              params.row.usdtRecharge == null
                ? "#"
                : this.Fixed(params.row.usdtRecharge)
            );
          }
        },
         {
          title: "累计扣除ESTATE",
          align: "center",
          key: "estateReduceRecharge",
          render: (h, params) => {
            return h(
              "div",
              params.row.estateReduceRecharge == null
                ? "#"
                : this.Fixed(params.row.estateReduceRecharge)
            );
          }
        },
         {
          title: "累计扣除USDT",
          align: "center",
          key: "usdtReduceRecharge",
          render: (h, params) => {
            return h(
              "div",
              params.row.usdtReduceRecharge == null
                ? "#"
                : this.Fixed(params.row.usdtReduceRecharge)
            );
          }
        }
        // {
        // 	title: '累计理财（EXUU数量）',
        // 	align: 'center',
        // 	key: 'financialNum',
        // 	render: (h, params) => {
        // 		return h('div', params.row.financialNum == null ? '#' : this.Fixed(params.row.financialNum, 4))
        // 	}
        // },
        // {
        // 	title: '累计推荐奖',
        // 	align: 'center',
        // 	key: 'recommend',
        // 	render: (h, params) => {
        // 		return h('div', params.row.recommend == null ? '#' : this.Fixed(params.row.recommend, 4))
        // 	}
        // },
        // {
        // 	title: '累计节点奖',
        // 	align: 'center',
        // 	key: 'noteAward',
        // 	render: (h, params) => {
        // 		return h('div', params.row.noteAward == null ? '#' : this.Fixed(params.row.noteAward, 4))
        // 	}
        // },
        // {
        // 	title: '累计网点奖励',
        // 	align: 'center',
        // 	key: 'netReward',
        // 	render: (h, params) => {
        // 		return h('div', params.row.netReward == null ? '#' : this.Fixed(params.row.netReward, 4))
        // 	}
        // }
      ]
    };
  },
  created() {},
  mounted() {
    this.$Message.config({
      top: 250
    });
    this.$nextTick(() => {
      this.getGcollect(); // 财务汇总统计查询
      this.getCollectList(); // 财务统计列表查询

      document.getElementById("today").innerHTML = "今日";
      let token = localStorage.getItem("mytoken");
      let params = this.qs.stringify({
        typeId: 1,
         startTime:
              this.dataValue[0] == "" ? "" : this.dataValue[0] + " 00:00:00",
            endTime:
              this.dataValue[1] == "" ? "" : this.dataValue[1] + " 23:59:59"
      });
      this.axios
        .post("/admin/accounting/statistical/time", params)
        .then(res => {
          if (res.data.code == 200) {

            this.timeGcollect = res.data.data;
          }
        });
    });
  },
  methods: {
    exportData() {
      this.jsonData = [];
      this.dcShow = true;
      this.axios
        .post(
          "/admin/accounting/statistical/list",
          this.qs.stringify({
            current: this.page,
            size: this.pageSize,
            startTime:
              this.dataValue[0] == "" ? "" : this.dataValue[0] + " 00:00:00",
            endTime:
              this.dataValue[1] == "" ? "" : this.dataValue[1] + " 23:59:59"
          })
        )
        .then(res => {
          if (res.data.code == 200) {
            this.axios
              .post(
                "/admin/accounting/statistical/list",
                this.qs.stringify({
                  current: 1,
                  size: res.data.data.total,
                  startTime:
                    this.dataValue[0] == ""
                      ? ""
                      : this.dataValue[0] + " 00:00:00",
                  endTime:
                    this.dataValue[1] == ""
                      ? ""
                      : this.dataValue[1] + " 23:59:59"
                })
              )
              .then(res => {
                if (res.data.code == 200) {
                 
                  this.downList = res.data.data.records;
                  this.downList.forEach((row, index) => {
                    this.jsonData.push({
                      times: this.stringToTime(this.downList[index].times),
                      estateAccrual: this.Fixed(
                        this.downList[index].estateAccrual,
                        4
                      ),
                      usdtAccrual: this.Fixed(
                        this.downList[index].usdtAccrual,
                        4
                      ),
                      estateWithdrawal: this.Fixed(
                        this.downList[index].estateWithdrawal,
                        4
                      ),
                      usdtWithdrawal: this.Fixed(
                        this.downList[index].usdtWithdrawal,
                        4
                      ),
                      estateRecharge: this.Fixed(
                        this.downList[index].estateRecharge,
                        4
                      ),
                      usdtRecharge: this.Fixed(
                        this.downList[index].usdtRecharge,
                        4
                      ),
                      // financialNum: this.Fixed(
                      //   this.downList[index].financialNum,
                      //   4
                      // ),
                      // recommend: this.Fixed(this.downList[index].recommend, 4),
                      // noteAward: this.Fixed(this.downList[index].noteAward, 4),
                      // netReward: this.Fixed(this.downList[index].netReward, 4)
                      estateReduceRecharge: this.Fixed(this.downList[index].estateReduceRecharge, 4),
                      usdtReduceRecharge: this.Fixed(this.downList[index].usdtReduceRecharge, 4),
                    });
                  });
                  let str = `日期,累计到账ESTATE,累计到账USDT,累计提现ESTATE,累计提现USDT,累计充值ESTATE,累计充值USDT,累计扣除ESTATE,累计扣除USDT\n`;
                  this.downLoad(this.jsonData, str, "财务统计");
                }
              });
          }
        });
    },
    // 处理时间段时间格式
    getTime(daterange) {
      this.dataValue = daterange;
    },
    getCollectList() {
      // 财务统计列表查询
      let token = localStorage.getItem("mytoken");
      let param = this.qs.stringify({
        current: this.page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        startTime:
          this.dataValue[0] == "" ? "" : this.dataValue[0] + " 00:00:00",
        endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + " 23:59:59"
      });
      this.axios.post("/admin/accounting/statistical/list", param).then(res => {
        if (res.data.code == 200) {
          this.collectList = res.data.data.records;
          this.info = res.data.data.total;
          this.loading = false;
        }
      });
    },
    cuctGetCollectList() {
      // 财务统计列表分页查询
      this.loading = true;
      let token = localStorage.getItem("mytoken");
      let params;
      if (this.dataValue.length > 2) {
        params = this.qs.stringify({
          current: this.page, // 当前页【可选，默认1】
          size: this.pageSize, // 每页记录数【可选，默认20】
          startTime:
            this.dataValue[0] == "" ? "" : this.dataValue[0] + " 00:00:00",
          endTime:
            this.dataValue[1] == "" ? "" : this.dataValue[1] + " 23:59:59"
        });
      } else {
        
        params = this.qs.stringify({
          current: this.page, // 当前页【可选，默认1】
          size: this.pageSize, // 每页记录数【可选，默认20】
          typeId:
            this.day == "今日"
              ? 1
              : this.day == "近7天"
              ? 2
              : this.day == "近30天"
              ? 3
              : 0
        
        });
      }

      this.axios
        .post("/admin/accounting/statistical/list", params)
        .then(res => {
          if (res.data.code == 200) {
            this.collectList = res.data.data.records;
            this.info = res.data.data.total;
            this.loading = false;
          }
        });
    },
    getCollectListQuery() {
      // 财务统计列表条件查询
      this.loading = true;
      let token = localStorage.getItem("mytoken");
      let params = this.qs.stringify({
        current: 1, // 当前页【可选，默认1】
        size: this.pageSize,
        startTime:
          this.dataValue[0] == "" ? "" : this.dataValue[0] + " 00:00:00",
        endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + " 23:59:59"
      });
      this.axios
        .post("/admin/accounting/statistical/list", params)
        .then(res => {
          if (res.data.code == 200) {
            this.page = 1;
            this.collectList = res.data.data.records;
            this.info = res.data.data.total;
            this.day =
              this.dataValue.length <= 0
                ? "2000-12-30 - 2200-12-30"
                : this.dataValue[0].replace(" 00:00:00", "") +
                  " - " +
                  this.dataValue[1].replace(" 00:00:00", "");
            this.loading = false;
          }
        });

      let params2 = this.qs.stringify({
        startTime:
          this.dataValue[0] == "" ? "" : this.dataValue[0] + " 00:00:00",
        endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + " 23:59:59"
      });
      this.axios
        .post("/admin/accounting/statistical/time", params2)
        .then(res => {
          if (res.data.code == 200) {
            this.timeGcollect = res.data.data;
          }
        });
    },
    getGcollect() {
      // 	财务统计汇总
      this.axios.get("/admin/accounting/statistical").then(res => {
        if (res.data.code == 200) {
          this.list = res.data.data;
        }
      });
    },
    getTimeGcollect(index) {
      // 时间段汇总
      this.getDate = "";
      if (index == 1) {
        this.day = "今日";
      }
      if (index == 2) {
        this.day = "近7天";
      }
      if (index == 3) {
        this.day = "近30天";
      }
      let token = localStorage.getItem("mytoken");
      let params = this.qs.stringify({
        typeId: index
      });
      this.current = 1;
      this.axios
        .post("/admin/accounting/statistical/time", params)
        .then(res => {
          if (res.data.code == 200) {
            this.timeGcollect = res.data.data;
            // localStorage.setItem('index',index)
          }
        });

      this.loading = true;
      let params2 = this.qs.stringify({
        current: 1, // 当前页【可选，默认1】
        size: this.pageSize,
        typeId: index
      });
      this.axios
        .post("/admin/accounting/statistical/list", params2)
        .then(res => {
          if (res.data.code == 200) {
            this.collectList = res.data.data.records;
            this.info = res.data.data.total;
            this.loading = false;
          }
        });
    }
  }
};
</script>
